package com.yh.correct.service.impl;

import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yh.correct.dao.IChatMapper;
import com.yh.correct.model.Chat;
import com.yh.correct.model.Page;
import com.yh.correct.service.IChatService;
/**
 * 实现个人谈话方案登记业务实现类
 * @author 陈帅
 *
 */


@Service
public class ChatServiceImpl implements IChatService {

	private static Logger logger = LogManager.getLogger(ProjectServiceImpl.class);
	
	@Autowired
	private IChatMapper chatMapper;
	
	/**
	 *根据id查询个人谈话方案
	 * @throws Exception 
	 */
	@Override
	public Map<String,Object> getChat(Chat c) throws Exception {
		// TODO Auto-generated method stub
		Map<String,Object> map;
		map=chatMapper.getChat(c);
		return map;
	}
	/**
	 *添加个人谈话方案
	 * @throws Exception 
	 */
	@Override
	public int addChat(Chat c) throws Exception {
		// TODO Auto-generated method stub
		logger.error("添加个人谈话："+c);
		return chatMapper.addChat(c);
	}
	/**
	 *删除个人谈话方案
	 * @throws Exception 
	 */
	@Override
	public int delChat(Chat c) throws Exception {
		// TODO Auto-generated method stub
		return chatMapper.delChat(c);
	}

	/**
	 *修改个人谈话方案
	 * @throws Exception 
	 */
	@Override
	public int editChat(Chat c) throws Exception {
		// TODO Auto-generated method stub
		return chatMapper.editChat(c);
	}
	/**
	 *根据姓名,日期模糊查询个人谈话方案
	 * @throws Exception 
	 */
	@Override
	public Page getLikeChats(Map<String, Object> condition) throws Exception {
			Page page=new Page();
			page.setTotalNum(chatMapper.getLikeChatsCount(condition));
			int pageSize = Integer.parseInt(String.valueOf(condition.get("pageSize")));
			page.setPageSize(pageSize);
			int curPageNum = Integer.parseInt(String.valueOf(condition.get("pageNum")));
			page.setCurPageNum(curPageNum);
			page.setTotalPage(page.getTotalNum()/pageSize+(page.getTotalNum()%pageSize==0?0:1));
			page.setResult(chatMapper.getLikeChats(condition));
			logger.debug("模糊查询个人谈话方案!");
			return page;
		
	}
	@Override
	public List<Map<String, Object>> getAllC() throws Exception {
		// TODO Auto-generated method stub
		return chatMapper.getAllC();
	}

}
